var t = function (t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(require("../../../../utils/toot.js")),
  a = getApp();
var bmap = require('../../../../utils/bmap-wx.min.js');
//假设签约为健康顾问
Page({
  data: {
    myDcoBoo: !0,
    modelBoo: !1,
    backBoo: !1,
    authState: null,
    id: 1,
    url: "patient/sign/doctorInfo/get/",
    doctor: {
      jobType: 1,
      patientCount: 100,
      askNum: 10,
      userIcon: "/assets/images/796.png"
    },
    service: [{
      cdInterroga: 290101,
      currentPrice: 1000,
      servicePrice: 2000
    },
    {
      cdInterroga: 290102,
      currentPrice: 1000,
      servicePrice: 2000
    },
    ],
    options: 0,
    works: [{
      title: '说说怎么预防感冒',
      tiem: '50',
      money: ''
    },
    {
      title: '说说怎么预防感冒',
      tiem: '50',
      money: '50'
    },
    {
      title: '说说怎么预防感冒',
      tiem: '50',
      money: '10'
    },
    {
      title: '说说怎么预防感冒',
      tiem: '50',
      money: '80'
    },
    {
      title: '说说怎么预防感冒',
      tiem: '50',
      money: '50'
    },
    {
      title: '说说怎么预防感冒',
      tiem: '50',
      money: '10'
    },
    {
      title: '说说怎么预防感冒',
      tiem: '50',
      money: '80'
    }
    ],
    servicePackage: [{
      title: '手术快约',
      state: 0,
      id: 1
    },
    {
      title: '专家坐诊',
      state: 1,
      id: 2
    },
    {
      title: '点名会诊',
      state: 0,
      id: 3
    }
    ],
    specialService: [{
      effect: 80,
      satisfied: 60,
      about: 200,
      title: '换骨头方案'
    },
    {
      effect: 80,
      satisfied: 60,
      about: 200,
      title: '换骨头方案'
    },
    {
      effect: 80,
      satisfied: 60,
      about: 200,
      title: '换骨头方案'
    },
    {
      effect: 80,
      satisfied: 60,
      about: 200,
      title: '换骨头方案'
    },
    {
      effect: 80,
      satisfied: 60,
      about: 200,
      title: '换骨头方案'
    }
    ],
    myDoctor: '', //健康顾问
    myNurse: '', //护理顾问
    myTeam: '', //团队顾问
    lookOverBoo: 0, //0为可签约
    relation: {
      signState: 2, //显示当前用户与顾问状态 0为  1为   2为可签约
    },
    confirmFlag: 0, //0为已签约成功 1为还没有签约成功
    reasonList: ['技术菜', '收费高', '不回信息'],
  },
  onLoad: function (o) {
    var that = this
    var zid = o.zid
    var juli = o.juli
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    //console.log(juli)
    a.util.request({
      'url': "entry/wxapp/Zhuanjiaxiangqing",
      data: {
        id: zid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          xiangqing: res.data.data,
          shanchang: res.data.data.shanchang
        })
      },
      fail: function (err) {
        // console.log(err)
      },
    })
    
    this.getAllteam(zid)
    this.getZhuanjiakeshi(zid)
    this.loadInfo();
    var BMap = new bmap.BMapWX({
      ak: '4DGFO0htsrocLEd7iQefj7F9tL1Fw1Xn'
    });
    var fail = function (data) {
      console.log(data)
    };
    var success = function (data) {
      console.log(data)
      // wxMarkerData = data.wxMarkerData;
      wxMarkerData = that.data.array
      that.setData({
        markers: wxMarkerData,
      });
    }
    that.setData({
      juli: juli,
      zid: zid
    })
  },
  selectBtn: function (e) {
    console.log(e)
    if (0 != this.data.doctor.activeFlag) {
      var t = this;
      if (1 == t.data.personalFlag)
        if (t.data.personalArr.gender && t.data.personalArr.name && t.data.personalArr.phone) {
          if (0 != t.data.myDoctor.length) return console.log(111), void t.setData({
            yetFlag: !0,
            yetMsg: "当前您已与其他健康顾问签约，不能再签约此健康顾问，需要与当前健康顾问解约后，才能与此健康顾问签约。",
            targetDoctor: t.data.myDoctor
          });
          if (0 != t.data.myNurse.length) return console.log(2222), void t.setData({
            yetFlag: !0,
            yetMsg: "当前您已与护理顾问签约，不能再签约健康顾问，需要与护理顾问解约后，才能与健康顾问签约。",
            targetDoctor: t.data.myNurse
          });
          if (0 != t.data.myTeam.length) return console.log(3333), void t.setData({
            yetFlag: !0,
            yetMsg: "当前您已与团队顾问签约，不能再签约健康顾问，需要与团队顾问解约后，才能与健康顾问签约。",
            targetDoctor: t.data.myTeam
          });
          this.setData({
            modelBoo: !0
          });
        } else wx.showModal({
          title: "个人信息未完善",
          cancelText: "以后再说",
          confirmText: "去完善",
          confirmColor: "#3b4ca9",
          success: function (t) {
            t.confirm && wx.navigateTo({
              url: "/hyb_yl/userShopping/pages/index1/index1"
            });
          }
        });
      else {
        if (0 != t.data.myDoctor.length) return console.log(111), void t.setData({
          yetFlag: !0,
          yetMsg: "当前您已与其他健康顾问签约，不能再签约此健康顾问，需要与当前健康顾问解约后，才能与此健康顾问签约。",
          targetDoctor: t.data.myDoctor
        });
        if (0 != t.data.myNurse.length) return console.log(2222), void t.setData({
          yetFlag: !0,
          yetMsg: "当前您已与护理顾问签约，不能再签约健康顾问，需要与护理顾问解约后，才能与健康顾问签约。",
          targetDoctor: t.data.myNurse
        });
        if (0 != t.data.myTeam.length) return console.log(3333), void t.setData({
          yetFlag: !0,
          yetMsg: "当前您已与团队顾问签约，不能再签约健康顾问，需要与团队顾问解约后，才能与健康顾问签约。",
          targetDoctor: t.data.myTeam
        });
        this.setData({
          modelBoo: !0
        });
      }
    } else {
      var a = this.data.doctor.stopMedNotify || "";
      wx.showModal({
        title: "停诊中",
        content: a,
        showCancel: !1,
        confirmText: "取消",
        confirmColor: "#3b4ca9",
        success: function (t) {
          t.confirm;
        }
      });
    }
  },
  abolishBtn: function () {
    this.setData({
      modelBoo: !1
    });
  },
  //签约
  signedBtn: function () {
    var a = this;
    // t.default.signedBtn(a);
    // console.log(t)
    a.setData({
      // yetFlag: 2,
      myDoctor: 1,
      modelBoo: !1,
      'relation.signState': 0,
      backBoo: !0,
      lookOverBoo: 3
      // yetMsg: "请等待对方同意",
    })
    console.log(a.data.relation.signState)
    console.log(a.data.backBoo)
    // setTimeout(function() {
    //   a.setData({
    //     confirmFlag: 1,
    //     myDcoBoo: !1,
    //     lookOverBoo: 1,
    //     'relation.signState': 1
    //   })
    //   console.log(1)
    // }, 3000)
  },
  //取消申请
  cancelBtn: function (a) {
    var o = a.target.dataset.signid,
      that = this;
    that.setData({
      signId: o
    })
    let confirmFlag = that.data.confirmFlag;
    if (confirmFlag == 1) {
      wx.showModal({
        title: "团队已同意，不能取消申请",
        showCancel: !1,
        confirmText: "我知道了",
        confirmColor: "#3b4ca9",
        success: function () {
          that.setData({

          })
        }
      });
    } else {
      wx.showModal({
        title: "确定要取消申请吗？",
        confirmColor: "#3b4ca9"
      });
      that.setData({
        backBoo: !0,
        confirmFlag: 0,
        lookOverBoo: 2,
        'relation.signState': 2
      })
    }
    // , e.data.confirmFlag && (e.data.confirmFlag = !1), t.default.getDoctor(e);
  },
  //解约
  relieveBtn: function () {
    this.setData({
      ReasonFlag: !0,
    })
  },
  //确认解约
  confirmBtn: function () {
    this.setData({
      ReasonFlag: !1
    })
  },
  //去问诊
  goInquiry: function (e) {
    let index = e.currentTarget.dataset.index;
    let cdinterroga = this.data.service[index].cdInterroga;
    console.log(index)
    wx.navigateTo({
      url: "/hyb_yl/userCommunicate/pages/healthConsultant/healthConsultant?cdinterroga=" + cdinterroga
    });
  },
  //看作品
  works: function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/hyb_yl/backstageGroceries/pages/chatRom/chatRom',
    })
  },
  checkboxChange: function (a) {
    var o = this;
    // t.default.authorized(o, a);
  },
  //进入服务列表
  special: function (e) {
    console.log(e)
    let that = this;
    let id = e.currentTarget.dataset.id;
    let state = e.currentTarget.dataset.state;
    let index = e.currentTarget.dataset.index;
    let servicePackage = that.data.servicePackage[index].title;
    if (state == 0) {
      wx.showToast({
        title: servicePackage + '现在不约',
        icon: "none",
        duration: 2e3
      })
    } else {
      wx.navigateTo({
        url: '/hyb_yl/backstageGroceries/pages/choosePerson/choosePerson?id=' + id
      })
    }
  },
  //进入工作室
  studio: function (e) {
    var t_id = e.currentTarget.dataset.t_id
    wx.navigateTo({
      url: '/hyb_yl/backstageGroceries/pages/information2/information2?t_id=' + t_id
    })
  },
  onReady: function () { },
  onShow: function () {
    var o = this,
      e = this;
    1 == e.data.personalFlag && (this.data.token ? t.default.getBasicInfo(e) : wx.login({
      success: function (e) {
        var n = o,
          r = e.code;
        wx.request({
          url: a.globalData.httpLogin + "user/code",
          data: {
            code: r,
            token: n.data.token
          },
          success: function (a) {
            var o = a.data.data.token,
              e = a.data.data.bindPhone;
            n.setData({
              token: o
            });
            try {
              wx.setStorageSync("logs", o);
            } catch (t) { }
            try {
              wx.setStorageSync("bindPhone", e);
            } catch (t) { }
            t.default.getBasicInfo(n);
          },
          fail: function (t) { }
        });
      }
    }));
  },
  onHide: function () { },
  onUnload: function () {
    this.data.backBoo && wx.navigateBack({
      delta: 2
    });
  },
  noBtn: function () {
    this.setData({
      yetFlag: !1
    });
  },
  yetBtn: function () {
    return void this.setData({
      yetFlag: !1
    });
  },
  offBtn: function () {
    this.setData({
      ReasonFlag: !1
    });
  },
  // confirmBtn: function() {
  //   var a = this;
  //   if (a.data.oldDoctorId = a.data.doctorId, 0 != a.data.myTeam.length ? (a.data.doctorId = a.data.targetDoctor.teamId,
  //       a.data.oldUrl = a.data.url, a.data.url = "team/sign/info/") : a.data.doctorId = a.data.targetDoctor.doctorId,
  //     a.data.confirmFlag = !0, 0 == a.data.targetDoctor.signState) a.setData({
  //     signId: a.data.targetDoctor.signId
  //   }), t.default.getDoctor(a);
  //   else {
  //     if (a.setData({
  //         signId: a.data.targetDoctor.signId
  //       }), !this.data.reasonIndex || !this.data.reasonText) return void wx.showToast({
  //       title: "请选择解约原因",
  //       icon: "none",
  //       duration: 2e3
  //     });
  //     t.default.relieve(a);
  //   }
  //   wx.removeStorageSync("myDoctor"), wx.removeStorageSync("myNurse"), wx.removeStorageSync("myTeam"),
  //     a.data.myDoctor = [], a.data.myNurse = [], a.data.myTeam = [];
  // },
  chooseReason: function (t) {
    console.log(t), this.setData({
      reasonIndex: t.target.dataset.disreason,
      reasonText: t.target.dataset.text
    });
  },
  Select: function (a) {
    console.log(a)
    let that = this;
    let aaa = Number(a.target.dataset.current);
    this.setData({
      options: aaa
    });
  },
  loadInfo: function () {
    var page = this
    wx.getLocation({
      type: 'wgs84', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标  
      success: function (res) {
        console.log(res)
        var longitude = res.longitude
        var latitude = res.latitude
        page.loadCity(longitude, latitude)
        page.getAllzhuanjia(longitude, latitude)
      },
      fail: function () {
        // fail  
      },
      complete: function () {
        // complete  
      }
    })
  },
  loadCity: function (longitude, latitude) {
    var page = this
    wx.request({
      url: 'https://api.map.baidu.com/geocoder/v2/?ak=4DGFO0htsrocLEd7iQefj7F9tL1Fw1Xn&location=' + latitude + ',' + longitude + '&output=json',
      data: {},
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        var city = res.data.result.addressComponent.city;
        //查询当前城市的所有活动
        var lat = res.data.result.location.lat
        var lng = res.data.result.location.lng
        var sematic_description = res.data.result.sematic_description
        page.setData({
          city: city,
          lat: lat,
          lng: lng,
          sematic_description: sematic_description
        });

      },
      fail: function () {
        // fail  
      },
      complete: function () {
        // complete  
      }
    })
  },
  distance: function (la1, lo1, la2, lo2) {
    var La1 = la1 * Math.PI / 180.0;
    var La2 = la2 * Math.PI / 180.0;
    var La3 = La1 - La2;
    var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
    s = s * 6378.137; //地球半径
    s = Math.round(s * 10000) / 10000;
    console.log("计算结果", s)
    this.setData({
      s: s
    })
  },
  getAllzhuanjia: function (longitude, latitude) {
    var that = this
    var zid = that.data.zid
    a.util.request({
      'url': 'entry/wxapp/Zhuanjiajinw',
      data: {
        jingdu: longitude,
        latitude: latitude,
        zid: zid,
        op: 'post'
      },
      success: function (res) {
        console.log(res)
        var info = res.data.data
        that.distance(latitude, longitude, info.lat, info.jingdu)
        info.juli = that.data.s;
        that.setData({
          zhuanjia: info
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },
  getAllteam: function (zid){
    var that = this
    a.util.request({
      'url': 'entry/wxapp/Seledocteam',
      data: {
        zid: zid,
        teamtype: 0,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          myTeamList: res.data.data
        })
      }
    })
  },
  getZhuanjiakeshi: function (zid) {
    var that = this
    a.util.request({
      'url': 'entry/wxapp/Fabushare',
      data: {
        op: 'docfenxiang',
        zid: zid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          fxlist: res.data
        })
      }
    })
  }
});